package com.opengroupe.dto;

import java.io.Serializable;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.opengroupe.database.qRHSQLiteHelper;

public class ReponseDto implements Serializable{
	private static final long serialVersionUID = -7543675082406051063L;
	private Integer idReponse;
	private Integer idQuestion;
	private boolean correct;
	private String contenuReponse;

	public ReponseDto() {
	}

	public ReponseDto(int idReponse,String contenuReponse, boolean correct, int idQuestion) {
		this.idReponse = idReponse;
		this.contenuReponse = contenuReponse;
		this.correct = correct;
		this.idQuestion = idQuestion;
	}

	public Integer getIdReponse() {
		return this.idReponse;
	}

	public void setIdReponse(Integer idReponse) {
		this.idReponse = idReponse;
	}
	
	public Integer getIdQuestion() {
		return this.idQuestion;
	}

	public void setIdQuestion (Integer idQuestion) {
		this.idQuestion = idQuestion;
	}
	
	public boolean getCorrect() {
		return this.correct;
	}

	public void setIsCorrect(boolean correct) {
		this.correct = correct;
	}

	public String getContenuReponse() {
		return this.contenuReponse;
	}

	public void setContenuReponse(String contenuReponse) {
		this.contenuReponse = contenuReponse;
	}
	
	public void save(Context context)
	{
		qRHSQLiteHelper bddHelper = new qRHSQLiteHelper(context);
		SQLiteDatabase bdd = bddHelper.getWritableDatabase();
		
		
		
		ContentValues values = new ContentValues();
		values.put("contenu", contenuReponse);
		values.put("correcte", correct ? 1 : 0);
		
		if (idReponse == 0)
		{
			values.put("idQuestion", idQuestion);
			
			// insert
			long id= bdd.insert("reponse", null, values);
			idReponse = (int) id;
		}
		else
		{
			bdd.update("reponse", values, "id=?",new String[] { String.valueOf( this.idReponse) });
			
		}
		
		
		bdd.close();
		bddHelper.close();
		
	}
	
	public void delete(Context context)
	{
		qRHSQLiteHelper bddHelper = new qRHSQLiteHelper(context);
		SQLiteDatabase bdd = bddHelper.getWritableDatabase();			
		
		bdd.delete("reponse", "id=?",new String[] { String.valueOf( this.idReponse) });
		
		bdd.close();
		bddHelper.close();
		
	}

}
